<template>
    <view class="pages fitment-pages">
        <view class="content">
            <view class="_wish">心愿单</view>
            <template v-if="list.length > 0">
                <view class="Collection">已收藏{{list.length}}套房源</view>
                <wish-item v-for="(item,index) in list" :key="index" :data="item"></wish-item>
            </template>
            <view v-else>
                <u-empty mode="favor" text="还没有收藏房源" textSize="18" iconSize="100" marginTop="200rpx"></u-empty>
                <view style="margin: 60rpx">
                    <u-button type="primary" text="查看更多房源" @click="toIndexPage"></u-button>
                </view>
            </view>
        </view>
        <view class="safe-area-inset-bottom"></view>
        <bottom-navigation-bar></bottom-navigation-bar>
    </view>
</template>

<script>
    import bottomNavigationBar from "../../../components/bottom-navigation-bar";
    import WishItem from "./components/WishItem";

    export default {
        name: "index",
        components:{
            bottomNavigationBar,
            WishItem
        },
        data(){
            return{
                list:[],
            };
        },
        onLoad(){
            let userInfo = uni.getStorageSync('userInfo');
            let u_id = uni.getStorageSync('u_id');
            if (u_id && userInfo.mobile) {
                this.getWishList();
            }else {
                uni.navigateTo({url:'/pages/user/my/login'});
            }
        },
        methods:{
            getWishList(){
                if (this.u_id){
                    uni.$u.http.post('/api.php/UserClinet/wish_list', {u_id: this.u_id}).then(res => {
                        this.list = res;
                    })
                }
            },
            toIndexPage(){
                uni.setStorageSync('user_tab_bar', 0);
                uni.switchTab({url: '/pages/user/index/index'});
            },
        }
    }
</script>

<style scoped>
    .pages {
        width: 100%;
        min-height: 100vh;
        background-color: RGBA(245, 245, 245, 1);
    }
    .content{
        padding: 20rpx;
    }

    ._wish {
        font-size: 18px;
        font-weight: 600;
    }

    .Collection {
        font-size: 12px;
        margin-top: 20rpx;
        color: #9c9c9c;
    }

</style>